package com.yanqu.road.dao.impl.config;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.config.parergon.UnionParergonConfig;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.HashMap;
import java.util.Map;

public class UnionParergonConfigDaoImpl extends TempDao {
    public void getUnionParergonConfig(Map<Integer, Map<Integer, UnionParergonConfig>> map1, Map<Integer, UnionParergonConfig> map2) {
        ResultSet rs = null;
        CallableStatement call = null;
        String sql = "select * from t_p_union_parergon";
        try {
            getDb().setConnName(DbNameStrategy.getConfigDb());
            call = getDb().getConnection().prepareCall(sql);
            rs = call.executeQuery();
            while (rs.next()) {
                UnionParergonConfig data = new UnionParergonConfig();
                data.setId(rs.getInt("id"));
                data.setName(rs.getString("name"));
                data.setType(rs.getInt("type"));
                data.setQuality(rs.getInt("quality"));
                data.setProgress(rs.getInt("progress"));
                data.setManagePerProgress(rs.getInt("managePerProgress"));
                data.setRewards(rs.getString("rewards"));
                data.setManagePar(rs.getInt("managePar"));
                data.setDiscountShopPro(rs.getInt("discountShopPro"));

                Map<Integer, UnionParergonConfig> map = map1.get(data.getType());
                if (null == map) {
                    map = new HashMap<>();
                    map1.put(data.getType(), map);
                }
                map.put(data.getQuality(), data);

                map2.put(data.getId(), data);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            getDb().closeConnection(call, rs);
        }
    }
}
